﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

namespace YouTubeStormer
{
    class CommentVoting
    {
        Communications communications;

        public CommentVoting(Communications communications)
        {
            this.communications = communications;
        }

        public enum Result
        {
            Voted,
            AlreadyVoted,
            Errored
        }

        public Result PerformVote(out Main.DebugDataHelper DebugData, string videoID, CommentDetails.CommentDetail comment)
        {
            DebugData = new Main.DebugDataHelper();          

            string getUrl = Communications.YoutubeBaseUrl + "comment_voting?" +
                "a=" + "1" +
                "&id=" + comment.ID +
                "&video_id=" + videoID +
                "&old_vote=" + comment.Score +
                "&tag=" + comment.Tag;
            DebugData.Input = getUrl;

            string ResponseData = communications.PerformGet(
                getUrl,
                referer: Communications.YoutubeWatchUrl + videoID,
                host: Communications.YoutubeBareHostUrl,
                accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            DebugData.Output = ResponseData;

            if (ResponseData.Contains("ALREADY VOTED")) return Result.AlreadyVoted;
            else if (!ResponseData.Contains("comment-score")) return Result.Errored;
            else return Result.Voted;
        }

    }
}
